package com.prolestar.web.controller.notice;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.prolestar.common.annotation.Log;
import com.prolestar.common.core.controller.BaseController;
import com.prolestar.common.core.domain.AjaxResult;
import com.prolestar.common.core.page.TableDataInfo;
import com.prolestar.common.enums.BusinessType;
import com.prolestar.common.utils.poi.ExcelUtil;
import com.prolestar.notice.domain.PsNotice;
import com.prolestar.notice.domain.PsNoticeCondition;
import com.prolestar.notice.domain.PsNoticeDTO;
import com.prolestar.notice.domain.PsNoticeRecord;
import com.prolestar.notice.service.IPsNoticeService;
import com.prolestar.publicsentiment.domain.ApportionPubilcsentiment;
import com.prolestar.publicsentiment.domain.PsPublicsentiment;
import com.prolestar.util.MySetPage;

/**
 * 通知公告Controller
 * 
 * @author xuyp
 * @date 2022-11-12
 */
@RestController
@RequestMapping("/notice/notice")
public class PsNoticeController extends BaseController
{
    @Autowired
    private IPsNoticeService psNoticeService;

    /**
     * 查询通知公告列表
     */
    @PreAuthorize("@ss.hasPermi('notice:notice:list')")
    @GetMapping("/list")
    public TableDataInfo list(PsNotice psNotice)
    {
//        startPage();
        List<PsNotice> list = psNoticeService.selectPsNoticeList(psNotice);
//        return getDataTable(list);
        return MySetPage.mySetPage(list);
    }

    /**
     * 导出通知公告列表
     */
    @PreAuthorize("@ss.hasPermi('notice:notice:export')")
    @Log(title = "通知公告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PsNotice psNotice)
    {
        List<PsNotice> list = psNoticeService.selectPsNoticeList(psNotice);
        ExcelUtil<PsNotice> util = new ExcelUtil<PsNotice>(PsNotice.class);
        util.exportExcel(response, list, "通知公告数据");
    }

    /**
     * 获取通知公告详细信息
     */
    @PreAuthorize("@ss.hasPermi('notice:notice:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(psNoticeService.selectPsNoticeById(id));
    }

    /**
     * 修改通知公告
     */
    @PreAuthorize("@ss.hasPermi('notice:notice:edit')")
    @Log(title = "通知公告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PsNotice psNotice)
    {
        return toAjax(psNoticeService.updatePsNotice(psNotice));
    }

    /**
     * 删除通知公告
     */
    @PreAuthorize("@ss.hasPermi('notice:notice:remove')")
    @Log(title = "通知公告", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(psNoticeService.deletePsNoticeByIds(ids));
    }


    /**
     * 发布通知公告
     */
    @PreAuthorize("@ss.hasPermi('notice:notice:add')")
    @Log(title = "通知公告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult apportion(@RequestBody PsNoticeDTO psNoticeDTO){
        return psNoticeService.apportion(psNoticeDTO);
    }



    /**
     * 发布通知--反馈处置
     */
    @PostMapping("/dispose")
    public AjaxResult dispose(@RequestBody PsNoticeRecord psNoticeRecord){
        return psNoticeService.dispose(psNoticeRecord);
    }

    /**
     * 发布通知--已读
     */
    @PostMapping("/yesRead")
    public AjaxResult yesRead(@RequestBody PsNoticeRecord psNoticeRecord){
        return psNoticeService.yesRead(psNoticeRecord);
    }


    /**
     * 发布通知--撤回
     */
    @PostMapping("/withdraw")
    public AjaxResult withdraw(@RequestBody PsNotice psNotice){
        return psNoticeService.withdraw(psNotice);
    }

    /**
     * 发布通告--处置情况
     */
    @PostMapping("/dispositionList")
    public List<PsNoticeRecord> dispositionList(@RequestBody PsNoticeRecord psNoticeRecord){
        return psNoticeService.dispositionList(psNoticeRecord);
    }

    /**
     * 发布公告 --接受情况
     */
    @PostMapping("/acceptance")
    public PsNoticeCondition acceptance(@RequestBody PsNotice psNotice){
        return psNoticeService.acceptance(psNotice);

    }








}
